<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		 <!--[if lt IE 9]>
    <script src="../js/jquery-1.11.3.js"></script>
    
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="../js/jquery-3.1.1.js"></script>
<!--<![endif]-->
<script type="text/javascript">
$(document).ready(function(){
  $("p:only-of-type").css("background-color","yellow");
});
</script>

</head>
<body>
​
<div style="border:1px solid;">
<p>第一个段落</p>
<p>最后一个段落</p>
</div><br>
​
<div style="border:1px solid;">
<p>只有一个段落</p>
</div><br>
​
<div style="border:1px solid;">
<span>这是 span 元素</span>
<p>唯一的段落</p>
</div><br>
​
</body>
</html>
运行结果

Copyright © 2013-2017菜鸟教程